(function() {
  app.controller('vipDepositCtrl', function(alertTip, $stateParams, header_m, centerdilog, $scope, local_m, vipIndex, $state, bottomdilog, tradeApi) {
    header_m
      .set({
        txt_r: '追加',
        fun_r: function() {
          centerdilog
            .open({
              msg: $scope.client.occur_balance ? '确定要追加' + $scope.client.occur_balance + '元吗？' : '追加金额不能为空！',
              closetxt: '取消',
              ok: $scope.client.occur_balance ? $scope.ok : function() {},
            });
        },
      });

    $scope.init = function() {
      $scope.client = {};
      tradeApi
        .etQuery({
          funcid: '5',
        })
        .then(function(res) {
          $scope.vip_info = res[0];
        });

      tradeApi
        .query({
          funcId: '300004',
          data: {}
        })
        .then(function(res) {
          $scope.client_fund_info = res;
        });
      $scope.history();
    };

    $scope.ok = function() {
      tradeApi
        .query({
          funcId: '300033',
          data: {
            occur_balance: $scope.client.occur_balance,
            contract_id: $stateParams.contract_id
          }
        })
        .then(function(res) {
          alertTip.open({
            state: 1,
            msg: '追加保证金申请提交成功！',
          });
          $scope.init();
        });
    };

    $scope.history = function() {
      var audit_status_arr = ['未审核', '已通过', '已拒绝'];
      tradeApi
        .query({
          funcId: '300035',
          data: {
            business_type: '11',
            contract_id: $stateParams.contract_id
          }
        })
        .then(function(res) {
          angular.forEach(res, function(element) {
            element.rows_item_audit_status = audit_status_arr[element.audit_status];
          });
          $scope.rowList.data = res;
        });
    };

    $scope.rowList = {
      data: null,
      title: ['申请日期', '申请时间', '追加金额', '申请进度'],
      color_key: null,
      row1: [
        { key: 'occur_date' },
        { key: 'occur_time' },
        { key: 'occur_balance' },
        { key: 'rows_item_audit_status' },
      ],
      click: function(obj) {
        console.log(obj)
      },
    }
  });

})();